package com.atguigu.cloud.controller;

import com.atguigu.cloud.resp.ResultData;
import com.atguigu.cloud.service.StorageService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author bairimengchang
 * @version 1.0
 * @project cloud2024
 * @description
 * @date 2024/12/10
 */
@RestController
public class StorageController {

    @Resource
    private StorageService storageService;

    /**
     * 扣减库存，这个老师写个@RequestMapping就很迷，不写清楚请求类型
     * 这里应该跟feign接口的请求类型保持一致，理论上这里是更新操作，应该用PUT
     * 并且不应该这样传参，应该在请求体里操作@RequestBody
     * 但是feign接口还没改，所以只能跟着用Post
     */
//    @PostMapping("/storage/decrease")
    @PutMapping("/storage/decrease")
    public ResultData<String> decrease(@RequestParam(name = "productId") Long productId,
                                       @RequestParam(name = "count") Integer count) {

        storageService.decrease(productId, count);
        return ResultData.success("扣减库存成功!");
    }

}
